package com.red.controller.user;


import com.red.dto.ShoppingCarDTO;
import com.red.result.PageResult;
import com.red.result.Result;
import com.red.service.ShoppingCarService;
import com.red.vo.ShoppingCarVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCar")
@ApiModel(value = "购物车接口")
@Slf4j
public class ShoppingCarController {
    @Autowired
    private ShoppingCarService shoppingCarService;


    /**
     * 购物车查询
     * @return
     */
    @GetMapping("/shoppingCarAll")
    @ApiModelProperty("购物车查询")
    public Result<List<ShoppingCarVO>> pageQuery(){

        List<ShoppingCarVO> voList  = shoppingCarService.pageQuery();
        return Result.success(voList);
    }

    /**
     * 添加购物车
     * @param dto
     * @return
     */
    @PostMapping("/insert")
    @ApiModelProperty("添加购物车")
    public Result insert(@RequestBody ShoppingCarDTO dto){
        shoppingCarService.insert(dto);
        return Result.success();
    }

    /**
     * 删除购物车的一个商品
     */
    @DeleteMapping()
    @ApiModelProperty("删除购物车")
    public Result delete(@RequestBody ShoppingCarDTO dto){
        log.info("删除购物车信息{}",dto);
        shoppingCarService.delete(dto);
        return Result.success();
    }

    /**
     * 批量删除
     * @return
     */
    @DeleteMapping("/clean")
    @ApiModelProperty("批量删除")
    public Result clean(@RequestBody ShoppingCarDTO dto){
        log.info("ids {}",dto.getIds());
        shoppingCarService.clean(dto.getIds());
        return Result.success();
    }
}
